$(function () {
    var id = $("#id").val();
    var liveType = $("#type").val();
    $("body").on('click',"#copyUrl",function () {
        var liveid = $(this).data('liveid');
        copyUrl(liveid);
    }).on('click','#theTeacherLiveClient',function () {
        openInputName(1,id,1,liveType);
    }).on('click','#theTeacherLiveWebPage',function () {
        openInputName(1,id,2,liveType);
    }).on('click','#theTaLiveClient',function () {
        openInputName(2,id,1,liveType);
    }).on('click','#theTaLiveWebPage',function () {
        openInputName(2,id,2,liveType);
    }).on('click','#theHostLiveClient',function () {
        openInputName(3,id,1,liveType);
    }).on('click','#theHostLiveWebPage',function () {
        openInputName(3,id,2,liveType);
    })
})
function copyUrl(liveid) {
    var shareUrl_ = $("#shareUrl_"+liveid);
    shareUrl_.select();
    document.execCommand("Copy");
    layer.msg("已复制")
}

function openInputName(type,id,openType,liveType){
    parent.layer.closeAll();
    if (openType == '1') {
        parent.layer.open({
            content: '进入前需安装直播客户端，如已安装可点击进入即可！'
            ,title: '友情提示'
            , btn: ['进入直播间', '下载客户端']
            , yes: function (index, layero) {
                toLive(type, id, openType,liveType);
            }, btn2: function (index, layero) {
                window.location.href = "https://ftp.3ttech.cn/云中课堂.exe";
            }, cancel: function () {
            }
        });
    } else {
        toLive(type,id,openType,liveType)
    }
}

function toLive(type, id, openType,liveType) {
    var liveUrl = "";
    var _ele = $('#openInputName').val();
    if (type != 3) {
        parent.layer.closeAll();
        $.ajax({
            url: baseloaction + '/admin/toLiveByLink/getLiveParam',
            data: {'type': type, 'id': id, 'liveType': liveType},
            dataType: 'json',
            success: function (result) {
                if (result.success == true) {
                    if (openType == '1') {
                        liveUrl = "yzkt://quickenterlive&i=" + result.entity.UID + "&k=" + result.entity.safeKey + "&t=" + result.entity.timeStamp + "&r=" + result.entity.classId + "";
                        window.protocolCheck(
                            liveUrl,
                            function () {
                                icModale(0, "客户端软件未安装");
                            }
                        );
                        event.preventDefault ? event.preventDefault() : event.returnValue = false;
                    } else {
                        var url = result.entity.classRoomUrl;
                        $("#url").val(url);
                        $("#toLiveIframe").submit();
                    }
                } else {
                    icModale(0, result.message);
                }
            }
        });
    } else {
        var html = '请输入账号';
        parent.layer.open({
            type: 1,
            area: ['240px', '180px'],
            skin: 'layui-layer-demo',
            title: '<strong>' + html + '</strong>',
            content: _ele,
            btn: '确定',
            yes: function (index, layero) {
                var pass = layero.find('#rejectedCause').val();
                if (pass.length <= 0) {
                    icModale(0, html);
                    return;
                }
                if (pass.length >= 30) {
                    icModale(0, '不能大于30个字符');
                    return;
                }
                icModale(0, '进入中');
                $.ajax({
                    url: baseloaction + '/admin/toLiveByLink/getLiveParam',
                    data: {'type': type, 'id': id, 'liveType': liveType, 'name': pass},
                    dataType: 'json',
                    success: function (result) {
                        parent.layer.closeAll();
                        if (result.success == true) {
                            if (openType == '1') {
                                liveUrl = "yzkt://quickenterlive&i=" + result.entity.UID + "&k=" + result.entity.safeKey + "&t=" + result.entity.timeStamp + "&r=" + result.entity.classId + "";
                                window.protocolCheck(
                                    liveUrl,
                                    function () {
                                        icModale(0, "客户端软件未安装");
                                    }
                                );
                                event.preventDefault ? event.preventDefault() : event.returnValue = false;
                            } else {
                                var url = result.entity.classRoomUrl;
                                $("#url").val(url);
                                $("#toLiveIframe").submit();
                            }
                        } else {
                            icModale(0, result.message);
                        }
                    }
                });
            }
        });
    }
}